This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Cmd+Shift+Enter.
start_time <- Sys.time()
output_name <- "CA121_WT_GA_Metal_analysis"
control_ID <- "CA121 WT_dH2O"
protein_filter <- NA
ligand_filter <- NA
analysis_path <- './Analysis'
rawData_path <- './Raw'
# library('svglite')
library(ggplot2)
library(ggpubr)
Attaching package: ‘ggpubr’
The following object is masked from ‘package:TSAR’:
get_legend
library(readxl)
library(stringr)
library(tidyr)
Attaching package: ‘tidyr’
The following object is masked from ‘package:testthat’:
matches
library(dplyr)
Attaching package: ‘dplyr’
The following object is masked from ‘package:testthat’:
matches
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
library(readr)
Attaching package: ‘readr’
The following object is masked from ‘package:TSAR’:
write_file
The following objects are masked from ‘package:testthat’:
edition_get, local_edition
library(mgcv)
Loading required package: nlme
Attaching package: ‘nlme’
The following object is masked from ‘package:dplyr’:
collapse
This is mgcv 1.9-1. For overview type 'help("mgcv-package")'.
library(TSAR)
nAnalysis<- length(dir(path = analysis_path))
nRawData <- length(dir(path = rawData_path))
tsa_df <- merge_TSA(
analysis_file_path = dir(path = analysis_path,
full.names = TRUE),
raw_data_path = dir(path = rawData_path,
full.names = TRUE)
)
tsa_df
normalized_tsa_df <- normalize_fluorescence(tsa_data = tsa_df)
head(normalized_tsa_df)
library('svglite')
# names(normalized_tsa_df)[names(normalized_tsa_df) == "RFU"] <- "Normalized"
# TSA_compare_plotx(normalized_tsa_df,y = "RFU",control_condition = control_ID,show_Tm = T)
TSA_compare_plot(normalized_tsa_df, control_condition = control_ID,
y = "RFU", smoother = "beta",
beta_shape = 4, beta_knots_frac = 0.008)
$`CA121 WT_PF74`
$`CA121 WT_Gallic acid`
$`CA121 WT_FeCl3 + Gallic acid`
$`CA121 WT_CuCl2 + Gallic acid`
$`CA121 WT_CaCl2 + Gallic acid`
$`CA121 WT_MgCl2 + Gallic acid`
$`CA121 WT_NaCl + Gallic acid`
$`CA121 WT_FeCl3`
$`CA121 WT_CuCl2`
$`CA121 WT_CaCl2`
$`CA121 WT_MgCl2`
$`CA121 WT_NaCl`
$`Control: CA121 WT_dH2O`
# uncomment the following for plots generation
# for (nm in names(plots)) {
# # If your list contains NULLs (e.g. for unused slots), skip those:
# if (is.null(plots[[nm]])) next
#
# # Construct filename: e.g., "plot_ConditionA.svg"
# fname <- paste0("plot_", gsub("[^A-Za-z0-9_-]", "_", nm), ".svg")
# ggsave(filename = fname, plot = plots[[nm]], width = 6, height = 4, units = "in", device = "svg")
# }
# source("../R/tsa_curves.R")
for(i in 1:condition_IDs(normalized_tsa_df, n = TRUE)) {
cond_i <- condition_IDs(normalized_tsa_df)[i]
subset_i <- normalized_tsa_df$condition_ID == cond_i
subset_i <- normalized_tsa_df[subset_i, ]
# plot_i <- TSA_wells_plot(subset_i)
plot_i <- TSA_wells_plot(subset_i, y = "RFU", smooth = TRUE,
smoother = "beta", beta_shape = 4, beta_knots_frac = 0.008)
print(plot_i)
# uncomment the following for plots generation
# Create a filename for each condition
# svg_file <- paste0("tsa_plot_", gsub("[^A-Za-z0-9_-]", "_", cond_i), ".svg")
# Save the plot as SVG
# ggplot2::ggsave(filename = svg_file, plot = plot_i[[1]], device = "svg", width = 6, height = 4, units = "in")
}
[[1]]
[[2]]
[[1]]
[[2]]
[[1]]
[[2]]
[[1]]
[[2]]
[[1]]
[[2]]
[[1]]
[[2]]
[[1]]
[[2]]
[[1]]
[[2]]
[[1]]
[[2]]
[[1]]
[[2]]
[[1]]
[[2]]
[[1]]
[[2]]
[[1]]
[[2]]
# 1) Compare L2 (RMSE) across GAM and a small Beta grid
# source("../R/averageTSA.R")
res_L2 <- TSA_smoother_diagnostics(
normalized_tsa_df,
y = "RFU",
metric = "L2",
# beta_shapes = c(2, 4),
# beta_fracs = c(0.008, 0.02)
)
mean L2 error of gam method: 0.02851
mean L2 error of beta(a=4, frac=0.008): 0.01985
beta(a=4, frac=0.008) has lowest error and highest accuracy.
res_L2_df <- as.data.frame(res_L2)
res_L2_df
NA
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Cmd+Option+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Cmd+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.